/**
 * @Company 
 * @Title: LoginController.java 
 * @Package com.jbinfo.qingcaowan.app.controller 
 * @author lizhenwei
 * @date 2016-07-11 下午1:06:21 
 * @version V1.0   
 */
package com.jbinfo.qingcaowan.app.controller;

import java.util.Date;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jbinfo.qingcaowan.base.dto.BaseSignDTO;
import com.jbinfo.qingcaowan.base.service.BaseSignService;
import com.jbinfo.qingcaowan.common.JSONResult;

/**
 * @ClassName: LoginController
 * @Description: 签到controller
 * @author John Zhao
 */
/**
 * @author Administrator
 *
 */
@Controller
public class SignController {

	private static final Logger LOG = LoggerFactory.getLogger(SignController.class);

	@Resource
	private BaseSignService baseSignService;

	
	@RequestMapping(value = "/{client}/sign")
	public @ResponseBody
	Object userLogin(@PathVariable("client") String client
			, BaseSignDTO signDTO
			, HttpServletResponse response) {
		LOG.info("客户端为 " + client + " 签到时间：" + signDTO.getSignDate());
		
//		LoginContext loginContext = LoginContextUtil.getLoginContext(session);
//		
//		UserDTO userDTO = loginContext.getLoginUser();
//		String userId = signDTO.getUserId();
		
		//signDTO.setUserId(userId);
		signDTO.setSignDate(new Date());
		
		JSONResult jsonResult = (JSONResult) baseSignService.saveSign(signDTO);
		
		return jsonResult;
	}
	
	// 获取当天签到状态
	@RequestMapping(value = "/{client}/getSignStatus")
	public @ResponseBody
	Object getSignStatus(@PathVariable("client") String client
			, HttpServletResponse response
			, HttpSession session, BaseSignDTO signDTO) {
		LOG.info("客户端为 " + client + " 签到时间：" + signDTO.getSignDate());
		
//		LoginContext loginContext = LoginContextUtil.getLoginContext(session);
//		
//		UserDTO userDTO = loginContext.getLoginUser();
//		String userId = userDTO.getUserId();
//		
//		signDTO.setUserId(userId);
		signDTO.setSignDate(new Date());
		
		JSONResult jsonResult = (JSONResult) baseSignService.getSignStatus(signDTO);
		
		return jsonResult;
	}

}
